/**
 * @auther harfe
 * @date 2021/11/1 22:26
 */


import java.util.Arrays;

/**
 * 旋转图形（二维数组）
 */
public class RemovePic {
    public static void main(String[] args) {
        RemovePic removePic = new RemovePic();
        int[][] matrix = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
        for(int[] n : matrix){
            System.out.println(Arrays.toString(n));

        }
        removePic.rotate(matrix);
        for(int[] ans : matrix){
            System.out.println(Arrays.toString(ans));

        }
    }
    public void rotate(int[][] matrix) {
        int n = matrix.length;
        for (int i = 0; i < n / 2; i++) {
            int start = i;
            int end = n - i - 1;
            for(int j = 0;j < end - start; j++){
                int temp = matrix[start][start+j];
                matrix[start][start + j] = matrix[end - j][start];
                matrix[end - j][start] = matrix[end][end - j];
                matrix[end][end - j] = matrix[start + j][end];
                matrix[start + j][end] = temp;
            }
        }
    }
}
